<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>用户注册</title>
<link rel="stylesheet" href="__PUBLIC__/Mobile/css/zhang.css">
<script src="__PUBLIC__/Mobile/js/jquery-1.9.1.js"></script>
<script src="__PUBLIC__/Mobile/layer/layer.min.js"></script>
</head>

<body >
<form action="__SELF__" method="post" onSubmit="return check();">
<section>
<!--注册-->
<div class="lm"> 
	<a href="javascript:history.back(-1);">
		<img src="__PUBLIC__/Mobile/images/return.png" style="height:22px; line-height:22px; width:6%; padding-top:2%;" class="left">
	</a> 
    <span class="left size20">注册莫宁 </span>
</div>
<div class="Logon1">
	<p><b><img src="__PUBLIC__/Mobile/images/Phone.png"></b>
    <span>
	  <input name="phone" type="tel" placeholder="请输入11位手机号" class="size18" style="background:#FAFFBD;">
     <a href="javascript:void(0);" id="verify">获取验证码</a>   
      </span>
   </p>
	<p><b><img src="__PUBLIC__/Mobile/images/SMS.png"></b>
    <span>
	  <input name="yzm" type="text" placeholder="请输入短信验证码" class="size18" style="background:#FAFFBD;">
      </span>
   </p>
	<p><b><img src="__PUBLIC__/Mobile/images/password.png"></b>
    <span>
	  <input name="password" type="password" placeholder="请设置密码（6-16个字符）" class="size18" style="background:#FAFFBD;">
      </span>
   </p>
    <p>
	<b><img src="__PUBLIC__/Mobile/images/ID.png"></b>
   <span>
	  <input name="realname" id="realname"  type="text" placeholder="请输入真实姓名" class="size18" style="background:#FAFFBD;">
   </span>
</p>
<!-- 	<p>
	<b><img src="__PUBLIC__/Mobile/images/ID.png"></b>
   <span>
	  <input name="idcard" id="idcard" type="text" placeholder="请输入身份证号码" class="size18">
   </span>
</p>  --> 

	<p><b><img src="__PUBLIC__/Mobile/images/ID.png"></b>
	<if condition="$_COOKIE['mytuijianren'] neq 10000000">
	<input name="fid" type="text" value="{$_COOKIE['mytuijianren']}" placeholder="推荐人ID" class="size18" style="background:#FAFFBD;">
	<else/>
	<input name="fid" type="text" value="" placeholder="请输入推荐人ID" class="size18" style="background:#FAFFBD;">
	</if>
	  
   </p>
</div>
<div style="padding:15px; font-size:18px;">注：黄色框为必填项</div>
<button type="submit" class="immediately2 size26" style="border:none; font-size:1.5em;" id="button">注&nbsp;&nbsp;册</button>
</section>
</form>
<script>
	//获取验证码
	var yzm;
	
	$("#verify").click(function(){
		var validCode=true;
		var time=40;
		var codes=$(this);
		var phone = $("input[name=phone]").val();
		
		if(!phone){
			layer.msg('手机号码不能为空',2);
			return false;
		}
		layer.alert('验证码发送中',6);
		 $.ajax({
			 url: "{:U('User/reg_code')}",
	         type: "POST",
	         data: {phone:phone},
	         dataType: "json",
	         success: function(result){
	               if(result.isok=='ok'){
	            	   if (validCode) {
		        			validCode=false;
		        			codes.addClass("msgs1");
		        			var t=setInterval(function  () {
		        			time--;
		        			codes.html("等待"+time+"秒");
		        			if (time==0) {
		        				clearInterval(t);
		        			codes.html("重新获取");
		        				validCode=true;
		        			codes.removeClass("msgs1");
		        				}
		        			},1000)
		        		}
	            	   yzm = result.code;
	            	   layer.alert('验证码发送成功',6);
	               }else if(result.isok=='of'){
	            	   layer.alert('此账号已注册,您可以直接登录',3);
	               }else{
	            	   layer.msg('验证码未获取到',2);
	               }    
	         }
	     });
	});
	
	
	//用户注册
	function check(){
		var phone = $("input[name=phone]").val();
		var code = $("input[name=yzm]").val();
		var password = $("input[name=password]").val();
		var fid = $("input[name=fid]").val();
		//var idcard = $("#idcard").val();
		var realname = $("#realname").val();
		var reg_name = /^[·a-zA-Z\u4E00-\u9FA5]{2,13}$/;
		if(!phone){
			layer.msg('手机号码不能为空',2);
			return false;
		}
		if(!code){
			layer.msg('验证码不能为空',2);
			return false;
		}
		if(realname==''){
			layer.msg('姓名不能为空',2);
			return false;
		}
		if(!reg_name.test(realname)){
			layer.msg('姓名格式错误',2);
			return false;
		}
		
		if(!password){
			layer.msg('密码不能为空',2);
			return false;
		}
		if(!fid){
			layer.msg('推荐人ID不能为空',2);
			return false;
		}
		if(code != yzm ){
			layer.msg('验证码不正确',2);
			return false;
		}
		return true;
	}
</script>

</body>
</html>
